import tacticalApi from 'api/tactical'

// state
let state = {
  sportType: [],
  sportTypeList: [],
  detail: {},
  tacticalInfoContent: {}
}

// actions
const actions = {
  sportType ({ commit, state }, params) { // 获取运动类型
    return tacticalApi.sportType(params).then((json) => {
      commit('SPORTTYPE', {
        params: params,
        data: json.data.dicts
      })
    })
  },
  sportTypeList ({ commit, state }, params) { // 获取运动类型
    return tacticalApi.sportTypeList(params).then((json) => {
      commit('SPORTTYPELIST', {
        params: params,
        data: json.data
      })
    })
  },
  detail ({ commit, state }, params) { // 获取详情
    return tacticalApi.detail(params).then((json) => {
      commit('DETAIL', {
        params: params,
        data: json.data
      })
      return json.data
    }).then((res) => {
      commit('TACTICALINFOCONTENT', {
        data: JSON.parse(res.content)
      })
      return res.content
    })
  }
}
// mutations
const mutations = {
  SPORTTYPE (state, { data }) {
    state.sportType = data
  },
  SPORTTYPELIST (state, {data}) {
    state.sportTypeList = data
  },
  DETAIL (state, {data}) {
    state.detail = data
  },
  TACTICALINFOCONTENT (state, {data}) {
    state.tacticalInfoContent = data
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
